package cn.lsq.org.service.impl;

import cn.lsq.basic.utils.PageList;
import cn.lsq.org.domain.Shop;
import cn.lsq.org.mapper.ShopMapper;
import cn.lsq.org.query.ShopQuery;
import cn.lsq.org.service.ShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class ShopServiceImpl implements ShopService {
    @Autowired
    private ShopMapper shopMapper;
    @Override
    public List<Shop> loadAll() {
        return shopMapper.loadAll();
    }

    @Override
    public Shop loadById(Long id) {
        return shopMapper.loadById(id);
    }
    @Transactional
    @Override
    public void save(Shop shop) {
        shopMapper.save(shop);
    }
    @Transactional
    @Override
    public void remove(Long id) {
        shopMapper.remove(id);
    }
    @Transactional
    @Override
    public void update(Shop shop) {
        shopMapper.update(shop);
    }

    @Override
    public PageList<Shop> queryPage(ShopQuery shopQuery) {
        Long count = shopMapper.queryCount(shopQuery);
        if (count == 0){
            return new PageList<>();
        }
        List<Shop> shops = shopMapper.queryData(shopQuery);
        return new PageList<Shop>(count,shops);
    }
    @Override
    public void patchDelete(Long[] ids) {
        shopMapper.patchDelete(ids);
    }
}
